<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Navo Portable Library: navo/algorithm/nonlinear/binary/rblnk.h源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- 制作者 Doxygen 1.7.3 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Navo Portable Library&#160;<span id="projectnumber">Ver 1.0.20120827</span></div>
   <div id="projectbrief">Provides generic platform independent facilities.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="modules.html"><span>模块</span></a></li>
      <li><a href="annotated.html"><span>数据结构</span></a></li>
      <li class="current"><a href="files.html"><span>文件</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>文件列表</span></a></li>
      <li><a href="globals.html"><span>全局定义</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>navo/algorithm/nonlinear/binary/rblnk.h</h1>  </div>
</div>
<div class="contents">
<a href="rblnk_8h.html">浏览该文件的文档。</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */</span>
<a name="l00011"></a>00011 <span class="preprocessor">#ifdef _MSC_VER</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span><span class="preprocessor">#pragma once</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* #ifdef _MSC_VER */</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="preprocessor">#ifndef __NV_RBLNK__</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">#define __NV_RBLNK__</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="cdef_8h.html" title="Definitions and declarations for common constants, types, variables.">../../../port/cdef.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="integer_8h.html" title="Provides standard integer types.">../../../port/integer.h</a>&quot;</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {
<a name="l00023"></a>00023 <span class="preprocessor">#endif  </span><span class="comment">/* #ifdef __cplusplus */</span>
<a name="l00024"></a>00024 
<a name="l00031"></a>00031 <span class="preprocessor">#if defined(_MSC_VER) || defined(__CYGWIN__)</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#pragma pack(push, 2)</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* #if defined(_MSC_VER) || defined(__CYGWIN__) */</span>
<a name="l00034"></a>00034 
<a name="l00043"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7871f46c39842fab09b365dd88ac5cac">00043</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>intrin_align(2) <a class="code" href="struct____rblnk__node.html" title="红黑树节点">__rblnk_node</a>{
<a name="l00045"></a>00045     uintptr_t parent_color;
<a name="l00047"></a>00047     <span class="keyword">struct </span><a class="code" href="struct____rblnk__node.html" title="红黑树节点">__rblnk_node</a>* left;
<a name="l00049"></a>00049     <span class="keyword">struct </span><a class="code" href="struct____rblnk__node.html" title="红黑树节点">__rblnk_node</a>* right;
<a name="l00050"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf7a22577e5f8f2d8c3ab96f378465658">00050</a> }<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf7a22577e5f8f2d8c3ab96f378465658" title="节点">rblnk_node</a>, *<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga588a122bb585e30d2dbc7ef1e6cb0297" title="迭代器">rblnk_iter</a>;
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="preprocessor">#if defined(_MSC_VER) || defined(__CYGWIN__)</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#pragma pack(pop)</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* #if defined(_MSC_VER) || defined(__CYGWIN__) */</span>
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="preprocessor">#define RBLNK_RED       0 </span><span class="comment">/* 红色 */</span>
<a name="l00057"></a>00057 <span class="preprocessor">#define RBLNK_BLACK     1 </span><span class="comment">/* 黑色 */</span>
<a name="l00058"></a>00058 <span class="preprocessor">#define RBLNK_MASK      1 </span><span class="comment">/* 颜色掩码 */</span>
<a name="l00059"></a>00059 
<a name="l00064"></a><a class="code" href="structrblnk__root.html">00064</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>{
<a name="l00065"></a>00065     <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf7a22577e5f8f2d8c3ab96f378465658" title="节点">rblnk_node</a>* node;
<a name="l00066"></a>00066 }<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>;
<a name="l00067"></a>00067 
<a name="l00072"></a><a class="code" href="structrblnk__info.html">00072</a> <span class="keyword">typedef</span> <span class="keyword">struct </span>{
<a name="l00074"></a><a class="code" href="structrblnk__info.html#a76d971a3c552bc58ba9f0d5fceae9806">00074</a>     <span class="keywordtype">size_t</span> <a class="code" href="structrblnk__info.html#a76d971a3c552bc58ba9f0d5fceae9806" title="节点数">count</a>;
<a name="l00076"></a><a class="code" href="structrblnk__info.html#a820c167ceaaa9759b0ca2695d22db55c">00076</a>     <span class="keywordtype">size_t</span> <a class="code" href="structrblnk__info.html#a820c167ceaaa9759b0ca2695d22db55c" title="深度">depth</a>;
<a name="l00078"></a><a class="code" href="structrblnk__info.html#a62f3b2ad4f6c6147d1bb9a71dd8c9656">00078</a>     <span class="keywordtype">size_t</span> <a class="code" href="structrblnk__info.html#a62f3b2ad4f6c6147d1bb9a71dd8c9656" title="叶子数">leafs</a>;
<a name="l00079"></a>00079 }<a class="code" href="structrblnk__info.html" title="树信息表">rblnk_info</a>;
<a name="l00080"></a>00080 
<a name="l00092"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaaa8949a7bdda2793991e712c199486f8">00092</a> <span class="preprocessor">#define RBLNK_ROOT(name) rblnk_root name = {NULL}</span>
<a name="l00093"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga4889bf1e394402788acfc1a1de99be56">00093</a> <span class="preprocessor"></span><span class="preprocessor">#define RBLNK_NODE(name) rblnk_node name = {0, NULL, NULL}</span>
<a name="l00094"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaaa24fda3c1fa1489183288f405261c3a">00094</a> <span class="preprocessor"></span><span class="preprocessor">#define RBLNK_INFO(name) rblnk_info name = {0, 0, 0}</span>
<a name="l00095"></a>00095 <span class="preprocessor"></span>
<a name="l00102"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7417aa626d7a0f898b5338b97411d546">00102</a> <span class="keyword">typedef</span> int (*<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7417aa626d7a0f898b5338b97411d546" title="单参数回调函数指针">rblnk_pr1</a>)(<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf7a22577e5f8f2d8c3ab96f378465658" title="节点">rblnk_node</a>*);
<a name="l00103"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gad5fcd22dbb5992d65297e5663cb81d36">00103</a> <span class="keyword">typedef</span> int (*<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gad5fcd22dbb5992d65297e5663cb81d36" title="双参数回调函数指针">rblnk_pr2</a>)(<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf7a22577e5f8f2d8c3ab96f378465658" title="节点">rblnk_node</a>*, rblnk_node*);
<a name="l00104"></a>00104 
<a name="l00112"></a>00112 NV_API <span class="keywordtype">size_t</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6fb9e1cd4db306f16e55518361f0ab84" title="获取树的节点总数">rblnk_count</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root);
<a name="l00113"></a>00113 
<a name="l00122"></a>00122 NV_API <span class="keywordtype">size_t</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga8d93bfeca0ce469728f2b4c735ce106a" title="计算两个节点的迭代距离">rblnk_distance</a>(rblnk_iter first, rblnk_iter last);
<a name="l00123"></a>00123 
<a name="l00132"></a>00132 NV_API <span class="keywordtype">size_t</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga1de1ae60df6b6cfa2a6db141b00cc636" title="计算迭代器的正向索引">rblnk_index_of</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, rblnk_iter itr);
<a name="l00133"></a>00133 
<a name="l00142"></a>00142 NV_API <span class="keywordtype">size_t</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga29756a41c72f28650f4469334f43c015" title="计算迭代器的逆向索引">rblnk_reverse_index_of</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, rblnk_iter itr);
<a name="l00143"></a>00143 
<a name="l00151"></a>00151 NV_API <span class="keywordtype">size_t</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gacb852328ee3aacfe2e550c4b54b9949f" title="计算树的深度">rblnk_depth</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root);
<a name="l00152"></a>00152 
<a name="l00160"></a>00160 NV_API <span class="keywordtype">size_t</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gacae9fbde870cca412c6f6faee36ec142" title="计算树的叶子数">rblnk_leafs</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root);
<a name="l00161"></a>00161 
<a name="l00169"></a>00169 NV_API <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga3bf7056c3e0714a8e6aae9e91ce7e01e" title="获取树的信息，包括节点数、深度、叶子数">rblnk_get_info</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, <a class="code" href="structrblnk__info.html" title="树信息表">rblnk_info</a>* info);
<a name="l00170"></a>00170 
<a name="l00214"></a>00214 NV_API <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gade0f9a8b187659eb069ba5db9d8af195" title="插入节点后，对树进行着色调整">rblnk_coloring</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, rblnk_node* node, 
<a name="l00215"></a>00215                             rblnk_node* parent);
<a name="l00216"></a>00216 
<a name="l00223"></a>00223 NV_API <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga451886a62143e4743fafb5b86a5b2a28" title="移除某个节点">rblnk_erase</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, rblnk_node* entry);
<a name="l00224"></a>00224 
<a name="l00238"></a>00238 NV_API <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaa931c3dedfb8e0f288017fbf7a03b6b8" title="移除区域内的节点">rblnk_erases</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, rblnk_iter begin, 
<a name="l00239"></a>00239                         rblnk_iter end, <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7417aa626d7a0f898b5338b97411d546" title="单参数回调函数指针">rblnk_pr1</a> erase_handler);
<a name="l00240"></a>00240 
<a name="l00252"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga92211938608f69651c45516f2c85b663">00252</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga92211938608f69651c45516f2c85b663" title="初始化树根">rblnk_init</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root)
<a name="l00253"></a>00253 {
<a name="l00254"></a>00254     root-&gt;node = NULL;
<a name="l00255"></a>00255 }
<a name="l00256"></a>00256 
<a name="l00271"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7d050dc86491d48acbf588f40a48900f">00271</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7d050dc86491d48acbf588f40a48900f" title="判断树是否为空">rblnk_empty</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root)
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273     <span class="keywordflow">return</span> !root-&gt;node;
<a name="l00274"></a>00274 }
<a name="l00275"></a>00275 
<a name="l00276"></a>00276 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> __rblnk_singular(rblnk_node* root)
<a name="l00277"></a>00277 {
<a name="l00278"></a>00278     <span class="keywordflow">return</span> root &amp;&amp; !root-&gt;left &amp;&amp; !root-&gt;right;
<a name="l00279"></a>00279 }
<a name="l00280"></a>00280 
<a name="l00295"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaab20c46c2eb38254803490536bbc36ac">00295</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaab20c46c2eb38254803490536bbc36ac" title="判断树是否只有单个节点">rblnk_singular</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root)
<a name="l00296"></a>00296 {
<a name="l00297"></a>00297     <span class="keywordflow">return</span> __rblnk_singular(root-&gt;node);
<a name="l00298"></a>00298 }
<a name="l00299"></a>00299 
<a name="l00329"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga65fe4fdebdda77a66bb5b26d4c3c2910">00329</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga65fe4fdebdda77a66bb5b26d4c3c2910" title="判断树是否可以序列化">rblnk_serialable</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root)
<a name="l00330"></a>00330 {
<a name="l00331"></a>00331     <span class="keywordflow">return</span> !!root-&gt;node;
<a name="l00332"></a>00332 }
<a name="l00333"></a>00333 
<a name="l00341"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac7e13ffecf675371e361a25d258be3e7">00341</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac7e13ffecf675371e361a25d258be3e7" title="得到左子节点">rblnk_left</a>(rblnk_node* node)
<a name="l00342"></a>00342 {
<a name="l00343"></a>00343     <span class="keywordflow">return</span> node-&gt;left;
<a name="l00344"></a>00344 }
<a name="l00345"></a>00345 
<a name="l00353"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gabf511bf9afe0448fc2ea1a9feaf77935">00353</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gabf511bf9afe0448fc2ea1a9feaf77935" title="得到右子节点">rblnk_right</a>(rblnk_node* node)
<a name="l00354"></a>00354 {
<a name="l00355"></a>00355     <span class="keywordflow">return</span> node-&gt;right;
<a name="l00356"></a>00356 }
<a name="l00357"></a>00357 
<a name="l00364"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac9b28b4b852f74baf30eda817e2144b1">00364</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac9b28b4b852f74baf30eda817e2144b1" title="得到父节点">rblnk_parent</a>(rblnk_node* node)
<a name="l00365"></a>00365 {
<a name="l00366"></a>00366     <span class="keywordflow">return</span> (rblnk_iter)(node-&gt;parent_color &amp; (~RBLNK_MASK));
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 
<a name="l00377"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6abde00d596cf397ea6ccc5e5724f1e0">00377</a> <span class="keyword">static</span> <span class="keyword">inline</span> uintptr_t <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6abde00d596cf397ea6ccc5e5724f1e0" title="得到节点的颜色值">rblnk_color</a>(rblnk_node* node)
<a name="l00378"></a>00378 {
<a name="l00379"></a>00379     <span class="keywordflow">return</span> (node-&gt;parent_color &amp; RBLNK_MASK);
<a name="l00380"></a>00380 }
<a name="l00381"></a>00381 
<a name="l00390"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7f6bea5de9fffaed975df98753c20bed">00390</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7f6bea5de9fffaed975df98753c20bed" title="判断节点是否是红色的">rblnk_red</a>(rblnk_node* node)
<a name="l00391"></a>00391 {
<a name="l00392"></a>00392     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6abde00d596cf397ea6ccc5e5724f1e0" title="得到节点的颜色值">rblnk_color</a>(node) == RBLNK_RED;
<a name="l00393"></a>00393 }
<a name="l00394"></a>00394 
<a name="l00403"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6e91c6985df0a43de84afc2c55d47c04">00403</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6e91c6985df0a43de84afc2c55d47c04" title="判断节点是否是黑色的">rblnk_black</a>(rblnk_node* node)
<a name="l00404"></a>00404 {
<a name="l00405"></a>00405     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6abde00d596cf397ea6ccc5e5724f1e0" title="得到节点的颜色值">rblnk_color</a>(node) == RBLNK_BLACK;
<a name="l00406"></a>00406 }
<a name="l00407"></a>00407 
<a name="l00416"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga40cf982b1d6c159daa42defa32844502">00416</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga40cf982b1d6c159daa42defa32844502" title="判断当前节点是否是根节点">rblnk_is_root</a>(rblnk_iter itr)
<a name="l00417"></a>00417 {
<a name="l00418"></a>00418     <span class="keywordflow">return</span> !<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac9b28b4b852f74baf30eda817e2144b1" title="得到父节点">rblnk_parent</a>(itr);
<a name="l00419"></a>00419 }
<a name="l00420"></a>00420 
<a name="l00429"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga3acf0e85dbc729b064ccc9d696b194d4">00429</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga3acf0e85dbc729b064ccc9d696b194d4" title="判断当前节点是否是叶子节点">rblnk_is_leaf</a>(rblnk_iter itr)
<a name="l00430"></a>00430 {
<a name="l00431"></a>00431     <span class="keywordflow">return</span> !itr-&gt;left &amp;&amp; !itr-&gt;right;
<a name="l00432"></a>00432 }
<a name="l00433"></a>00433 
<a name="l00445"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gada1dad989f8a0d4cc3d49fefdfbf04fc">00445</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gada1dad989f8a0d4cc3d49fefdfbf04fc" title="链接两个节点">rblnk_link</a>(rblnk_iter newly, rblnk_iter parent, 
<a name="l00446"></a>00446                                 rblnk_iter* plink)
<a name="l00447"></a>00447 {
<a name="l00448"></a>00448     <span class="comment">/* 简单地将newly节点链接到parent节点下 */</span>
<a name="l00449"></a>00449     *plink = newly;
<a name="l00450"></a>00450     newly-&gt;left = NULL;
<a name="l00451"></a>00451     newly-&gt;right = NULL;
<a name="l00452"></a>00452     <span class="comment">/* 新节点默认是红色的 */</span>
<a name="l00453"></a>00453     newly-&gt;parent_color = (uintptr_t)parent;
<a name="l00454"></a>00454 }
<a name="l00455"></a>00455 
<a name="l00461"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga3943690f21dc9dee488c35313f7d093f">00461</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga3943690f21dc9dee488c35313f7d093f" title="设置当前节点的颜色为红色">rblnk_set_red</a>(rblnk_node* node)
<a name="l00462"></a>00462 {
<a name="l00463"></a>00463     node-&gt;parent_color &amp;= (~RBLNK_MASK);
<a name="l00464"></a>00464 }
<a name="l00465"></a>00465 
<a name="l00471"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga700dde2e01a11e733893be4dccaca0c6">00471</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga700dde2e01a11e733893be4dccaca0c6" title="设置当前节点的颜色为黑色">rblnk_set_black</a>(rblnk_node* node)
<a name="l00472"></a>00472 {
<a name="l00473"></a>00473     node-&gt;parent_color = RBLNK_BLACK | 
<a name="l00474"></a>00474         (node-&gt;parent_color &amp; (~RBLNK_MASK));
<a name="l00475"></a>00475 }
<a name="l00476"></a>00476 
<a name="l00483"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gab43d3dd00f5f9797f2e6728804388546">00483</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gab43d3dd00f5f9797f2e6728804388546" title="设置当前节点的颜色">rblnk_set_color</a>(rblnk_node* node, uintptr_t color)
<a name="l00484"></a>00484 {
<a name="l00485"></a>00485     node-&gt;parent_color = color | 
<a name="l00486"></a>00486         (node-&gt;parent_color &amp; (~RBLNK_MASK));
<a name="l00487"></a>00487 }
<a name="l00488"></a>00488 
<a name="l00496"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6f05bc6d011c149bc85e3667240a6f27">00496</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6f05bc6d011c149bc85e3667240a6f27" title="设置当前节点的父节点">rblnk_set_parent</a>(rblnk_node* node, rblnk_node* parent)
<a name="l00497"></a>00497 {
<a name="l00498"></a>00498     node-&gt;parent_color = (uintptr_t)(parent) | 
<a name="l00499"></a>00499         (node-&gt;parent_color &amp; RBLNK_MASK);
<a name="l00500"></a>00500 }
<a name="l00501"></a>00501 
<a name="l00509"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga5474c6caddd6bdba98f8e126d411d580">00509</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga5474c6caddd6bdba98f8e126d411d580" title="仅在node不为空时，设置node的父节点">rblnk_set_parent_if</a>(rblnk_node* node, rblnk_node* parent)
<a name="l00510"></a>00510 {
<a name="l00511"></a>00511     <span class="keywordflow">if</span> (node)
<a name="l00512"></a>00512         <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6f05bc6d011c149bc85e3667240a6f27" title="设置当前节点的父节点">rblnk_set_parent</a>(node, parent);
<a name="l00513"></a>00513 }
<a name="l00514"></a>00514 
<a name="l00523"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga53c43d6dc5b3cb6ab7a416fae7c5f80a">00523</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga53c43d6dc5b3cb6ab7a416fae7c5f80a" title="同时设置节点的父节点和颜色值">rblnk_set_parent_color</a>(rblnk_node* node, 
<a name="l00524"></a>00524                         rblnk_node* parent, uintptr_t color)
<a name="l00525"></a>00525 {
<a name="l00526"></a>00526     node-&gt;parent_color = (uintptr_t)(parent) | color;
<a name="l00527"></a>00527 }
<a name="l00528"></a>00528 
<a name="l00534"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga553fbabdc6b8bfa429d2a8dd41be744c">00534</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga553fbabdc6b8bfa429d2a8dd41be744c" title="初始化节点">rblnk_node_init</a>(rblnk_node* node)
<a name="l00535"></a>00535 {
<a name="l00536"></a>00536     node-&gt;parent_color = 0;
<a name="l00537"></a>00537     node-&gt;left = NULL;
<a name="l00538"></a>00538     node-&gt;right = NULL;
<a name="l00539"></a>00539 }
<a name="l00540"></a>00540 
<a name="l00549"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gadfe6e5c9ffa167c1536634f45c9ff8ce">00549</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gadfe6e5c9ffa167c1536634f45c9ff8ce" title="用新节点替换旧节点">rblnk_iter_replace</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, rblnk_iter victim, 
<a name="l00550"></a>00550                                       rblnk_iter newly)
<a name="l00551"></a>00551 {
<a name="l00552"></a>00552     rblnk_iter parent = <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac9b28b4b852f74baf30eda817e2144b1" title="得到父节点">rblnk_parent</a>(victim);
<a name="l00553"></a>00553     
<a name="l00554"></a>00554     <span class="comment">/* 将victim父节点的孩子设为newly */</span>
<a name="l00555"></a>00555     <span class="keywordflow">if</span> (parent) {
<a name="l00556"></a>00556         <span class="keywordflow">if</span> (victim == parent-&gt;left)
<a name="l00557"></a>00557             parent-&gt;left = newly;
<a name="l00558"></a>00558         <span class="keywordflow">else</span>
<a name="l00559"></a>00559             parent-&gt;right = newly;
<a name="l00560"></a>00560     } <span class="keywordflow">else</span>
<a name="l00561"></a>00561         root-&gt;node = newly;
<a name="l00562"></a>00562     
<a name="l00563"></a>00563     <span class="comment">/* 重新确定victim孩子节点的父节点为newly */</span>
<a name="l00564"></a>00564     <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga5474c6caddd6bdba98f8e126d411d580" title="仅在node不为空时，设置node的父节点">rblnk_set_parent_if</a>(victim-&gt;left, newly);
<a name="l00565"></a>00565     <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga5474c6caddd6bdba98f8e126d411d580" title="仅在node不为空时，设置node的父节点">rblnk_set_parent_if</a>(victim-&gt;right, newly);
<a name="l00566"></a>00566     
<a name="l00567"></a>00567     <span class="comment">/* 替换节点成员 */</span>
<a name="l00568"></a>00568     *newly = *victim;
<a name="l00569"></a>00569 }
<a name="l00570"></a>00570 
<a name="l00577"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga786e6ac4f90eaed9db8547e2c2a20b72">00577</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga786e6ac4f90eaed9db8547e2c2a20b72" title="用新的树根替换旧树根">rblnk_replace</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* victim, <a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* newly)
<a name="l00578"></a>00578 {
<a name="l00579"></a>00579     newly-&gt;node = victim-&gt;node;
<a name="l00580"></a>00580 }
<a name="l00581"></a>00581 
<a name="l00588"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga9dacf7edeb485b8997ff6cac7846a0c5">00588</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga9dacf7edeb485b8997ff6cac7846a0c5" title="交换两个树">rblnk_swap</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* a, <a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* b)
<a name="l00589"></a>00589 {
<a name="l00590"></a>00590     rblnk_iter t = a-&gt;node; a-&gt;node = b-&gt;node; b-&gt;node = t;
<a name="l00591"></a>00591 }
<a name="l00592"></a>00592 
<a name="l00602"></a>00602 NV_API <span class="keywordtype">int</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga43f9873a6ad90b95af037efd8b715313" title="判断一个节点是否存在于树中">rblnk_exist</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, rblnk_iter itr);
<a name="l00603"></a>00603 
<a name="l00612"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga282ecc18962ddc54b578df7044dc9de9">00612</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga282ecc18962ddc54b578df7044dc9de9" title="得到正向索引对应的节点的迭代器">rblnk_at</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, <span class="keywordtype">size_t</span> index)
<a name="l00613"></a>00613 {
<a name="l00614"></a>00614     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gae9ac9b2b5c33a92e0306a09346ef32cc" title="给迭代器增加一段距离或减小一段距离">rblnk_advance</a>(<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gab434b46c3cb032b3114a0c292ee50c52" title="得到树的最左端节点">rblnk_front</a>(root), index);
<a name="l00615"></a>00615 }
<a name="l00616"></a>00616 
<a name="l00626"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf747daec306db3fdfaa6653558ce2062">00626</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf747daec306db3fdfaa6653558ce2062" title="得到逆向索引对应的节点的迭代器">rblnk_reverse_at</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, <span class="keywordtype">size_t</span> index)
<a name="l00627"></a>00627 {
<a name="l00628"></a>00628     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gae9ac9b2b5c33a92e0306a09346ef32cc" title="给迭代器增加一段距离或减小一段距离">rblnk_advance</a>(<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga78d61eaa02e5a1af07b2da867776fd53" title="得到树的最右端节点">rblnk_back</a>(root), -(<span class="keywordtype">int</span>)(index));
<a name="l00629"></a>00629 }
<a name="l00630"></a>00630 
<a name="l00638"></a>00638 NV_API rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gab434b46c3cb032b3114a0c292ee50c52" title="得到树的最左端节点">rblnk_front</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root);
<a name="l00639"></a>00639 
<a name="l00647"></a>00647 NV_API rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga78d61eaa02e5a1af07b2da867776fd53" title="得到树的最右端节点">rblnk_back</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root);
<a name="l00648"></a>00648 
<a name="l00656"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gad090e3e5ab9b4f09b94e968233554a6b">00656</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gad090e3e5ab9b4f09b94e968233554a6b" title="得到指向正向起始位置的迭代器">rblnk_begin</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root)
<a name="l00657"></a>00657 {
<a name="l00658"></a>00658     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gab434b46c3cb032b3114a0c292ee50c52" title="得到树的最左端节点">rblnk_front</a>(root);
<a name="l00659"></a>00659 }
<a name="l00660"></a>00660 
<a name="l00667"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac850e7c259076759a9a8d5fde09e2104">00667</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gac850e7c259076759a9a8d5fde09e2104" title="得到指向正向终止位置的迭代器">rblnk_end</a>()
<a name="l00668"></a>00668 {
<a name="l00669"></a>00669     <span class="keywordflow">return</span> NULL;
<a name="l00670"></a>00670 }
<a name="l00671"></a>00671 
<a name="l00679"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga9af3a349f64b4e1476c529187f24d4bd">00679</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga9af3a349f64b4e1476c529187f24d4bd" title="得到当前迭代器的正向终止位置">rblnk_end_of</a>(rblnk_iter cur)
<a name="l00680"></a>00680 {
<a name="l00681"></a>00681     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga724a069a61ec122e5a22a515eb6fc1ab" title="得到当前节点的中序后继节点">rblnk_next</a>(cur);
<a name="l00682"></a>00682 }
<a name="l00683"></a>00683 
<a name="l00691"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gae58917b51be46e3525e90954cd3ab664">00691</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gae58917b51be46e3525e90954cd3ab664" title="得到指向逆向起始位置的迭代器">rblnk_rbegin</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root)
<a name="l00692"></a>00692 {
<a name="l00693"></a>00693     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga78d61eaa02e5a1af07b2da867776fd53" title="得到树的最右端节点">rblnk_back</a>(root);
<a name="l00694"></a>00694 }
<a name="l00695"></a>00695 
<a name="l00702"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga34d7b697a7bff2a1a90796e9c384f293">00702</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga34d7b697a7bff2a1a90796e9c384f293" title="得到指向逆向终止位置的迭代器">rblnk_rend</a>()
<a name="l00703"></a>00703 {
<a name="l00704"></a>00704     <span class="keywordflow">return</span> NULL;
<a name="l00705"></a>00705 }
<a name="l00706"></a>00706 
<a name="l00714"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaa826e37d560cfadd9527078b7541a8d5">00714</a> <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaa826e37d560cfadd9527078b7541a8d5" title="得到当前迭代器的逆向终止位置">rblnk_rend_of</a>(rblnk_iter cur)
<a name="l00715"></a>00715 {
<a name="l00716"></a>00716     <span class="keywordflow">return</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf2372e7e19baf6c5fc1c2d1e46bcda2a" title="得到当前节点的中序前驱节点">rblnk_prev</a>(cur);
<a name="l00717"></a>00717 }
<a name="l00718"></a>00718 
<a name="l00726"></a>00726 NV_API rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga724a069a61ec122e5a22a515eb6fc1ab" title="得到当前节点的中序后继节点">rblnk_next</a>(rblnk_iter cur);
<a name="l00727"></a>00727 
<a name="l00735"></a>00735 NV_API rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf2372e7e19baf6c5fc1c2d1e46bcda2a" title="得到当前节点的中序前驱节点">rblnk_prev</a>(rblnk_iter cur);
<a name="l00736"></a>00736 
<a name="l00744"></a>00744 NV_API rblnk_iter <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gae9ac9b2b5c33a92e0306a09346ef32cc" title="给迭代器增加一段距离或减小一段距离">rblnk_advance</a>(rblnk_iter cur, <span class="keywordtype">int</span> dist);
<a name="l00745"></a>00745 
<a name="l00756"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7b860940aefd704957bb73e2a56a1584">00756</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7b860940aefd704957bb73e2a56a1584" title="清空树">rblnk_clear</a>(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7417aa626d7a0f898b5338b97411d546" title="单参数回调函数指针">rblnk_pr1</a> erase_handler)
<a name="l00757"></a>00757 {
<a name="l00758"></a>00758     <span class="keywordflow">if</span> (!<a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga7d050dc86491d48acbf588f40a48900f" title="判断树是否为空">rblnk_empty</a>(root))
<a name="l00759"></a>00759         <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaa931c3dedfb8e0f288017fbf7a03b6b8" title="移除区域内的节点">rblnk_erases</a>(root, <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gab434b46c3cb032b3114a0c292ee50c52" title="得到树的最左端节点">rblnk_front</a>(root), NULL, erase_handler);
<a name="l00760"></a>00760 }
<a name="l00761"></a>00761 
<a name="l00762"></a>00762 <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter __rblnk_inc_later(rblnk_iter cur, rblnk_iter* p)
<a name="l00763"></a>00763 {
<a name="l00764"></a>00764     *p = <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga724a069a61ec122e5a22a515eb6fc1ab" title="得到当前节点的中序后继节点">rblnk_next</a>(cur);
<a name="l00765"></a>00765     <span class="keywordflow">return</span> cur;
<a name="l00766"></a>00766 }
<a name="l00767"></a>00767 
<a name="l00768"></a>00768 <span class="keyword">static</span> <span class="keyword">inline</span> rblnk_iter __rblnk_dec_later(rblnk_iter cur, rblnk_iter* p)
<a name="l00769"></a>00769 {
<a name="l00770"></a>00770     *p = <a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaf2372e7e19baf6c5fc1c2d1e46bcda2a" title="得到当前节点的中序前驱节点">rblnk_prev</a>(cur);
<a name="l00771"></a>00771     <span class="keywordflow">return</span> cur;
<a name="l00772"></a>00772 }
<a name="l00773"></a>00773 
<a name="l00784"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gabed6ad3d2a4042d6a2c382515eb95393">00784</a> <span class="preprocessor">#define rblnk_inc(itr)          ((itr) = rblnk_next(itr))</span>
<a name="l00785"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga5eef1427f5a3b2719c945271d9daeab6">00785</a> <span class="preprocessor"></span><span class="preprocessor">#define rblnk_dec(itr)          ((itr) = rblnk_prev(itr))</span>
<a name="l00786"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga8c62a05a3806b173f707611bdd76a1b0">00786</a> <span class="preprocessor"></span><span class="preprocessor">#define rblnk_inc_later(itr)    __rblnk_inc_later(itr, &amp;(itr))</span>
<a name="l00787"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga4565f33ce42fa4b1915ceb138646ba2c">00787</a> <span class="preprocessor"></span><span class="preprocessor">#define rblnk_dec_later(itr)    __rblnk_dec_later(itr, &amp;(itr))</span>
<a name="l00788"></a>00788 <span class="preprocessor"></span>
<a name="l00798"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga5b33334a44a642a1bf038efb405cd749">00798</a> <span class="preprocessor">#define rblnk_foreach(_begin, _end, fn, type, member) do {\</span>
<a name="l00799"></a>00799 <span class="preprocessor">        rblnk_iter _q_e = (_end);                           \</span>
<a name="l00800"></a>00800 <span class="preprocessor">        rblnk_iter _q_f = (_begin);                         \</span>
<a name="l00801"></a>00801 <span class="preprocessor">        while (_q_f != _q_e) {                              \</span>
<a name="l00802"></a>00802 <span class="preprocessor">            type * _q_t = container_of(_q_f, type, member); \</span>
<a name="l00803"></a>00803 <span class="preprocessor">            rblnk_inc(_q_f);                                \</span>
<a name="l00804"></a>00804 <span class="preprocessor">            fn(_q_t);                                       \</span>
<a name="l00805"></a>00805 <span class="preprocessor">        }                                                   \</span>
<a name="l00806"></a>00806 <span class="preprocessor">    } while (0)</span>
<a name="l00807"></a>00807 <span class="preprocessor"></span>
<a name="l00817"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga0610f520cada9850c8f805072925983b">00817</a> <span class="preprocessor">#define rblnk_reverse_foreach(_rbegin, _rend, fn, type, member) do {\</span>
<a name="l00818"></a>00818 <span class="preprocessor">        rblnk_iter _q_e = (_rend);                          \</span>
<a name="l00819"></a>00819 <span class="preprocessor">        rblnk_iter _q_f = (_rbegin);                        \</span>
<a name="l00820"></a>00820 <span class="preprocessor">        while (_q_f != _q_e) {                              \</span>
<a name="l00821"></a>00821 <span class="preprocessor">            type * _q_t = container_of(_q_f, type, member); \</span>
<a name="l00822"></a>00822 <span class="preprocessor">            rblnk_dec(_q_f);                                \</span>
<a name="l00823"></a>00823 <span class="preprocessor">            fn(_q_t);                                       \</span>
<a name="l00824"></a>00824 <span class="preprocessor">        }                                                   \</span>
<a name="l00825"></a>00825 <span class="preprocessor">    } while (0)</span>
<a name="l00826"></a>00826 <span class="preprocessor"></span>
<a name="l00827"></a>00827 NV_API <span class="keywordtype">void</span> __do_rblnk_recurse_foreach(rblnk_iter cur, 
<a name="l00828"></a>00828                         <span class="keywordtype">void</span> (*fn)(<span class="keywordtype">void</span>*), <span class="keywordtype">size_t</span> offset);
<a name="l00829"></a>00829 
<a name="l00830"></a>00830 NV_API <span class="keywordtype">void</span> __do_rblnk_recurse_reverse_foreach(rblnk_iter cur, 
<a name="l00831"></a>00831                         <span class="keywordtype">void</span> (*fn)(<span class="keywordtype">void</span>*), <span class="keywordtype">size_t</span> offset);
<a name="l00832"></a>00832 
<a name="l00833"></a>00833 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> __rblnk_recurse_foreach(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, 
<a name="l00834"></a>00834                         <span class="keywordtype">void</span> (*fn)(<span class="keywordtype">void</span>*), <span class="keywordtype">size_t</span> offset)
<a name="l00835"></a>00835 {
<a name="l00836"></a>00836     <span class="keywordflow">if</span> (fn)
<a name="l00837"></a>00837         __do_rblnk_recurse_foreach(root-&gt;node, fn, offset);
<a name="l00838"></a>00838 }
<a name="l00839"></a>00839 
<a name="l00840"></a>00840 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> __rblnk_recurse_reverse_foreach(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, 
<a name="l00841"></a>00841                             <span class="keywordtype">void</span> (*fn)(<span class="keywordtype">void</span>*), <span class="keywordtype">size_t</span> offset)
<a name="l00842"></a>00842 {
<a name="l00843"></a>00843     <span class="keywordflow">if</span> (fn)
<a name="l00844"></a>00844         __do_rblnk_recurse_reverse_foreach(root-&gt;node, fn, offset);
<a name="l00845"></a>00845 }
<a name="l00846"></a>00846 
<a name="l00855"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga709e8c44e4601a37834635c210548668">00855</a> <span class="preprocessor">#define RBLNK_RECURSE_PROC(name, type, param) void name(type * param)</span>
<a name="l00856"></a>00856 <span class="preprocessor"></span>
<a name="l00880"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga6df5839a68f52ca58b94baabc15d770e">00880</a> <span class="preprocessor">#define rblnk_recurse_foreach(root, fn, type, member) \</span>
<a name="l00881"></a>00881 <span class="preprocessor">    __rblnk_recurse_foreach(root, (void (*)(void*))(fn), \</span>
<a name="l00882"></a>00882 <span class="preprocessor">            offset_of(type, member))</span>
<a name="l00883"></a>00883 <span class="preprocessor"></span>
<a name="l00893"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga707fdda966662b8b02188fa4078931ba">00893</a> <span class="preprocessor">#define rblnk_recurse_reverse_foreach(root, fn, type, member) \</span>
<a name="l00894"></a>00894 <span class="preprocessor">    __rblnk_recurse_reverse_foreach(root, (void (*)(void*))(fn), \</span>
<a name="l00895"></a>00895 <span class="preprocessor">            offset_of(type, member))</span>
<a name="l00896"></a>00896 <span class="preprocessor"></span>
<a name="l00925"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#ga338edc24658c52267bcb1ee30527e165">00925</a> <span class="preprocessor">#define rblnk_search(root, newly, greater, res, type, member) do {\</span>
<a name="l00926"></a>00926 <span class="preprocessor">        rblnk_root* _k_r = (root);                              \</span>
<a name="l00927"></a>00927 <span class="preprocessor">        type * _k_pn = (newly);                                 \</span>
<a name="l00928"></a>00928 <span class="preprocessor">        rblnk_iter _k_p = _k_r-&gt;node;                           \</span>
<a name="l00929"></a>00929 <span class="preprocessor">        (res) = NULL;                                           \</span>
<a name="l00930"></a>00930 <span class="preprocessor">        while (_k_p) {                                          \</span>
<a name="l00931"></a>00931 <span class="preprocessor">            type * _k_pr = container_of(_k_p, type, member);    \</span>
<a name="l00932"></a>00932 <span class="preprocessor">            if (greater(_k_pr, _k_pn))                          \</span>
<a name="l00933"></a>00933 <span class="preprocessor">                _k_p = _k_p-&gt;left;                              \</span>
<a name="l00934"></a>00934 <span class="preprocessor">            else if (greater(_k_pn, _k_pr))                     \</span>
<a name="l00935"></a>00935 <span class="preprocessor">                _k_p = _k_p-&gt;right;                             \</span>
<a name="l00936"></a>00936 <span class="preprocessor">            else {                                              \</span>
<a name="l00937"></a>00937 <span class="preprocessor">                (res) = _k_p; break;                            \</span>
<a name="l00938"></a>00938 <span class="preprocessor">            }                                                   \</span>
<a name="l00939"></a>00939 <span class="preprocessor">        }                                                       \</span>
<a name="l00940"></a>00940 <span class="preprocessor">    } while (0)</span>
<a name="l00941"></a>00941 <span class="preprocessor"></span>
<a name="l00970"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gad12070580ff757a695a49faaa9c3cefb">00970</a> <span class="preprocessor">#define rblnk_insert(root, newly, greater, res, type, member) do {\</span>
<a name="l00971"></a>00971 <span class="preprocessor">        rblnk_root* _k_r = (root);                                      \</span>
<a name="l00972"></a>00972 <span class="preprocessor">        rblnk_iter* _k_pp = &amp;_k_r-&gt;node;                                \</span>
<a name="l00973"></a>00973 <span class="preprocessor">        rblnk_iter _k_n = (newly);                                      \</span>
<a name="l00974"></a>00974 <span class="preprocessor">        rblnk_iter _k_p;                                                \</span>
<a name="l00975"></a>00975 <span class="preprocessor">        type * _k_pn = container_of(_k_n, type, member);                \</span>
<a name="l00976"></a>00976 <span class="preprocessor">        (res) = 1;                                                      \</span>
<a name="l00977"></a>00977 <span class="preprocessor">        rblnk_node_init(_k_n);                                          \</span>
<a name="l00978"></a>00978 <span class="preprocessor">        while (*_k_pp) {                                                \</span>
<a name="l00979"></a>00979 <span class="preprocessor">            type * _k_pr = container_of(_k_p = *_k_pp, type, member);   \</span>
<a name="l00980"></a>00980 <span class="preprocessor">            if (greater(_k_pr, _k_pn))                                  \</span>
<a name="l00981"></a>00981 <span class="preprocessor">                _k_pp = &amp;_k_p-&gt;left;                                    \</span>
<a name="l00982"></a>00982 <span class="preprocessor">            else if (greater(_k_pn, _k_pr))                             \</span>
<a name="l00983"></a>00983 <span class="preprocessor">                _k_pp = &amp;_k_p-&gt;right;                                   \</span>
<a name="l00984"></a>00984 <span class="preprocessor">            else {                                                      \</span>
<a name="l00985"></a>00985 <span class="preprocessor">                (res) = 0; break;                                       \</span>
<a name="l00986"></a>00986 <span class="preprocessor">            }                                                           \</span>
<a name="l00987"></a>00987 <span class="preprocessor">        }                                                               \</span>
<a name="l00988"></a>00988 <span class="preprocessor">        if (res) {                                                      \</span>
<a name="l00989"></a>00989 <span class="preprocessor">            rblnk_link(_k_n, _k_p, _k_pp);                              \</span>
<a name="l00990"></a>00990 <span class="preprocessor">            rblnk_coloring(_k_r, _k_n, _k_p);                           \</span>
<a name="l00991"></a>00991 <span class="preprocessor">        }                                                               \</span>
<a name="l00992"></a>00992 <span class="preprocessor">    } while (0)</span>
<a name="l00993"></a>00993 <span class="preprocessor"></span>
<a name="l00994"></a>00994 NV_API <span class="keywordtype">void</span> __rblnk_serialize(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, <span class="keywordtype">void</span>** buf, <span class="keywordtype">size_t</span> offset);
<a name="l00995"></a>00995 
<a name="l00996"></a>00996 NV_API <span class="keywordtype">void</span> __rblnk_deserialize(<a class="code" href="structrblnk__root.html" title="树根">rblnk_root</a>* root, <span class="keywordtype">void</span>** buf, 
<a name="l00997"></a>00997                                     <span class="keywordtype">size_t</span> cnt, <span class="keywordtype">size_t</span> offset);
<a name="l00998"></a>00998 
<a name="l01008"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gacaec0cfff7eb3001fe7b1d67b2d4fda0">01008</a> <span class="preprocessor">#define rblnk_serialize(root, buf, type, member) \</span>
<a name="l01009"></a>01009 <span class="preprocessor">    __rblnk_serialize(root, (void**)(buf), offset_of(type, member))</span>
<a name="l01010"></a>01010 <span class="preprocessor"></span>
<a name="l01021"></a><a class="code" href="group___xE7_xBA_xA2_xE9_xBB_x91_xE6_xA0_x91.html#gaa3905e4e6ba16c931fe97b3e43384360">01021</a> <span class="preprocessor">#define rblnk_deserialize(root, buf, cnt, type, member) \</span>
<a name="l01022"></a>01022 <span class="preprocessor">    __rblnk_deserialize(root, (void**)(buf), cnt, offset_of(type, member))</span>
<a name="l01023"></a>01023 <span class="preprocessor"></span>
<a name="l01026"></a>01026 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l01027"></a>01027 <span class="preprocessor"></span>}
<a name="l01028"></a>01028 <span class="preprocessor">#endif  </span><span class="comment">/* #ifdef __cplusplus */</span>
<a name="l01029"></a>01029 
<a name="l01030"></a>01030 <span class="preprocessor">#endif  </span><span class="comment">/* #ifndef __NV_RBLNK__ */</span>
<a name="l01031"></a>01031 
</pre></div></div>
</div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>全部</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>数据结构</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>文件</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>函数</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>变量</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>类型定义</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>宏定义</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr class="footer"/><address class="footer"><small>Generated at 2015年七月16日 星期四 12:00:37 for Navo Portable Library by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>
